package cn.com.connext.scrm.repository.master;

import cn.com.connext.scrm.domain.master.PrizeRate;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * 2 * @Author: shawn
 * 3 * @Date: 2020/8/11 4:18 下午
 * 4
 */
@Repository
public interface PrizeRateRepository extends JpaRepository<PrizeRate, Integer> {

    @Query(value = "select end from prize_rate where good_id in (?1) order by end desc limit 1", nativeQuery = true)
    Integer getMaxNum(List<Integer> enableGoodIds);

    @Query(value = "select good_id from prize_rate where start <= ?1 and end >= ?1 ", nativeQuery = true)
    Integer getGoodId(Integer randomNum);

    @Query(value = "select * from prize_rate where good_id in (?1)", nativeQuery = true)
    List<PrizeRate> getByGoodId(List<Integer> enableGoodIds);

    /**
     * 获取各个商品中奖几率
     * @param list
     * @return
     */
    @Query(value = "select * from prize_rate where good_id in (?1) ", nativeQuery = true)
    List<PrizeRate> getEnableGood(List<Integer> list);

    PrizeRate findByGoodId(Integer goodId);
}
